package com.ks.user.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ks.core.base.OperationContext;
import com.ks.core.constant.Const;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.core.util.ToolUtil;
import com.ks.user.entity.LogOperatelog;
import com.ks.user.dao.LogOperatelogMapper;
import com.ks.user.entity.vo.CustomParam;
import com.ks.user.entity.vo.OperateUserRelation;
import com.ks.user.service.ILogOperatelogService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ks.user.service._ServiceBase;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 日志-用户日常操作记录 服务实现类
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-30
 */
@Service
public class LogOperatelogServiceImpl extends _ServiceBase<LogOperatelogMapper, LogOperatelog> implements ILogOperatelogService {
    @Resource
    private LogOperatelogMapper LogOperatelogMapper;

    @Override
    public Map<String, Object> selectLog(OperationContext context, SearchCriteriaBase searchCriteriaBase) {
        Page page = new Page(searchCriteriaBase.getPageIndex(), searchCriteriaBase.getLimit());
        CustomParam customParam = new CustomParam();
        ArrayList<SearchCriteriaBase.matchField> fields = searchCriteriaBase.getFields();
        if (ToolUtil.isNotEmpty(fields)) {
            for (SearchCriteriaBase.matchField field : fields) {
                if ("name".equals(field.getName())) {
                    customParam.setName(field.getValue());
                }
            }
        }
        if (ToolUtil.isNotEmpty(searchCriteriaBase.getStartTime())) {
            customParam.setStartTime(searchCriteriaBase.getStartTime());
        }
        if (ToolUtil.isNotEmpty(searchCriteriaBase.getEndTime())) {
            customParam.setEndTime(searchCriteriaBase.getEndTime());
        }
        List<OperateUserRelation> logOperatelogs = LogOperatelogMapper.OperateUserRelationInfo(page, customParam);
        int count = LogOperatelogMapper.OperateUserCount(customParam);
        Map<String, Object> ResultMap = isResultMap(logOperatelogs, searchCriteriaBase);
        ResultMap.put("count", count);
        return ResultMap;
    }

}
